package df.bean.db.table;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import df.bean.db.conn.DBConnection;
import df.bean.obj.util.JDate;
import df.bean.obj.util.JNumber;

public class SummaryMonthly extends ABSTable {
    
    private String yyyy = "";
    private String mm = "";
    private String transactionDate;
    private Double sumAmt = 0d;
    private Double sumDiscAmt = 0d;
    private Double sumPremiumAmt = 0d;
    private Double sumPatientPaidAmt = 0d;
    private Double drSumAmt = 0d;
    private Double drDiscAmt = 0d;
    private Double drPremiumAmt = 0d;
    private Double drCreditAmt = 0d;
    private Double drDebitAmt = 0d;
    private Double drNetPaidAmt = 0d;
    private Double drTax400 = 0d;
    private Double drTax401 = 0d;
    private Double drTax402 = 0d;
    private Double drTax406 = 0d;
    private Double hpSumAmt = 0d;
    private Double hpDiscAmt = 0d;
    private Double hpPremiumAmt = 0d;
    private Double hpTax = 0d;
    private String hospitalCode = "";
    private String doctorCode = "";
    private Double guarunteeAmt = 0d;
    private Double guarunteeTax = 0d;
    private String statusModify = "";
    private String batchNo = "";
    private String userID = "";
    private String updateDate = "";
    private String updateTime = "";
    private String oldDoctorCode = "";
    private String remark = "";
    private String paymentModeCode = "";
    private String refPaidNo = "";
    private String payDate = "";
    private String paymentTermDate = "";
    private Double drStepAmt = 0d;
    private Double hpStepAmt = 0d;
    private Double sumPremiumRecAmt = 0d;
    private Double sumPayByCash = 0d;
    private Double sumPayByAR = 0d;
    private Double cashAmt = 0d;
    private Double cash400 = 0d;
    private Double cash401 = 0d;
    private Double cash402 = 0d;
    private Double cash406 = 0d;
    private Double arAmt = 0d;
    private Double ar400 = 0d;
    private Double ar401 = 0d;
    private Double ar402 = 0d;
    private Double ar406 = 0d;
    private String tableName = "";
    private String isHold = "";
    
    public SummaryMonthly(DBConnection conn) {
        super();
        this.setDBConnection(conn);
        this.setSumAmt(0d);
        this.setSumDiscAmt(0d);
        this.setSumPatientPaidAmt(0d);
        this.setSumPremiumAmt(0d);
        this.setDrSumAmt(0d);
        this.setDrTax400(0d);
        this.setDrTax401(0d);
        this.setDrTax402(0d);
        this.setDrTax406(0d);
        this.setDrPremiumAmt(0d);
        this.setHpSumAmt(0d);
        this.setHpPremiumAmt(0d);
        this.setHpTax(0d);
        this.setDrStepAmt(0d);
        this.setHpStepAmt(0d);
        this.setSumPremiumRecAmt(0d);
        this.setSumPayByCash(0d);
        this.setSumPayByAR(0d);
        
        this.setCashAmt(0d);
        this.setCash400(0d);
        this.setCash401(0d);
        this.setCash402(0d);
        this.setCash406(0d);
        this.setArAmt(0d);
        this.setAr400(0d);
        this.setAr401(0d);
        this.setAr402(0d);
        this.setAr406(0d);
        this.setTableName("SUMMARY_MONTHLY");
        try {
            this.setStatement(this.getDBConnection().getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE));
        } catch (SQLException e) {
            // TODO
            System.out.print(e.getMessage());
        }
    }

    static public String getSQLSum_DAILY(String hospitalCode) {
        return  "select DOCTOR_CODE, sum(AMOUNT_AFT_DISCOUNT) as sinv_amt, sum(AMOUNT_OF_DISCOUNT) as sinv_discount_amt, " + 
                " sum(DR_AMT) as sDr_Amt,sum(DR_TAX_400) as sDr_Amt_400, sum(DR_TAX_401) as sDr_Amt_401, " + 
                " sum(DR_TAX_402) as sDr_Amt_402, sum(DR_TAX_406) as sDr_Amt_406,  sum(DR_PREMIUM) as sDr_Premium,  " + 
                " sum(HP_AMT) as sHp_Amt, sum(HP_PREMIUM) as sHp_Premium, sum(HP_TAX) as sHp_Tax,  " + 
                " sum(0) as sRec_Amt, sum(0) as sRec_Premium_Amt,  sum(PREMIUM_REC_AMT) as sPremium_Rec_Amt, " + 
                " SUM( CASE PAY_BY_AR WHEN 'Y' THEN 0 ELSE DR_AMT END ) AS sDr_Amt_CASH, " +
                " SUM( CASE PAY_BY_AR WHEN 'Y' THEN DR_AMT ELSE 0 END ) AS sDr_Amt_AR, " +
                // sum 
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN 0 ELSE DR_AMT END) AS sCash_Amt,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN 0 ELSE DR_TAX_400 END) AS sCash_400,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN 0 ELSE DR_TAX_401 END) AS sCash_401,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN 0 ELSE DR_TAX_402 END) AS sCash_402,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN 0 ELSE DR_TAX_406 END) AS sCash_406,  " +

                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN DR_AMT ELSE 0 END) AS sAr_Amt,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN DR_TAX_400 ELSE 0 END) AS sAr_400,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN DR_TAX_401 ELSE 0 END) AS sAr_401,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN DR_TAX_402 ELSE 0 END) AS sAr_402,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN DR_TAX_406 ELSE 0 END) AS sAr_406 " +
                
                //" FROM TRN_DAILY LEFT OUTER JOIN ORDER_ITEM ON TRN_DAILY.HOSPITAL_CODE = ORDER_ITEM.HOSPITAL_CODE" +
                //" AND TRN_DAILY.ORDER_ITEM_CODE = ORDER_ITEM.CODE"+
                " FROM TRN_DAILY " +
                    " where HOSPITAL_CODE ='" + hospitalCode + "'" + 
                    " and (BATCH_NO is null or BATCH_NO = '')" + 
                    " and YYYY='" + Batch.getYyyy() + "' and MM='" + Batch.getMm() + "'" +
                    " and DOCTOR_CODE is not null AND DOCTOR_CODE != ''" +
                    " and ACTIVE = '1' " +
                    " and ORDER_ITEM_ACTIVE = '1' "+
                    " and COMPUTE_DAILY_DATE is not null AND COMPUTE_DAILY_DATE != '' " +
                    " and (PAY_BY_CASH='Y' OR  PAY_BY_AR='Y' OR PAY_BY_DOCTOR='Y' OR PAY_BY_PAYOR='Y' OR PAY_BY_CASH_AR='Y' )" +
                    " and IS_PAID = 'Y' " +
                    " group By DOCTOR_CODE order by DOCTOR_CODE";
    }
    
    static public String getSQLSum_DAILYwithExcludeTreatment_Y(String hospitalCode) {
        return  "select DOCTOR_CODE, sum(AMOUNT_AFT_DISCOUNT) as sinv_amt, sum(AMOUNT_OF_DISCOUNT) as sinv_discount_amt, " + 
                " sum(DR_AMT) as sDr_Amt,sum(DR_TAX_400) as sDr_Amt_400, sum(DR_TAX_401) as sDr_Amt_401, " + 
                " sum(DR_TAX_402) as sDr_Amt_402, sum(DR_TAX_406) as sDr_Amt_406,  sum(DR_PREMIUM) as sDr_Premium,  " + 
                " sum(HP_AMT) as sHp_Amt, sum(HP_PREMIUM) as sHp_Premium, sum(HP_TAX) as sHp_Tax,  " + 
                " sum(0) as sRec_Amt, sum(0) as sRec_Premium_Amt,  sum(PREMIUM_REC_AMT) as sPremium_Rec_Amt, " + 
                " SUM( CASE PAY_BY_AR WHEN 'Y' THEN 0 ELSE DR_AMT END ) AS sDr_Amt_CASH, " +
                " SUM( CASE PAY_BY_AR WHEN 'Y' THEN DR_AMT ELSE 0 END ) AS sDr_Amt_AR, " +   
                // sum
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN 0 ELSE DR_AMT END) AS sCash_Amt,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN 0 ELSE DR_TAX_400 END) AS sCash_400,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN 0 ELSE DR_TAX_401 END) AS sCash_401,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN 0 ELSE DR_TAX_402 END) AS sCash_402,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN 0 ELSE DR_TAX_406 END) AS sCash_406,  " +

                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN DR_AMT ELSE 0 END) AS sAr_Amt,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN DR_TAX_400 ELSE 0 END) AS sAr_400,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN DR_TAX_401 ELSE 0 END) AS sAr_401,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN DR_TAX_402 ELSE 0 END) AS sAr_402,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN DR_TAX_406 ELSE 0 END) AS sAr_406 " +
                //" FROM TRN_DAILY LEFT OUTER JOIN ORDER_ITEM ON TRN_DAILY.HOSPITAL_CODE = ORDER_ITEM.HOSPITAL_CODE" +
                //" AND TRN_DAILY.ORDER_ITEM_CODE = ORDER_ITEM.CODE"+
                " FROM TRN_DAILY"+
                    " where HOSPITAL_CODE ='" + hospitalCode + "'" + 
                    " and (BATCH_NO is null or BATCH_NO = '')" + 
                    " and EXCLUDE_TREATMENT = 'Y' " +       // very important
                    " and YYYY='" + Batch.getYyyy() + "' and MM='" + Batch.getMm() + "'" +
                    " and DOCTOR_CODE is not null AND DOCTOR_CODE != '' " +
                    " and ACTIVE = '1' " +
                    " and ORDER_ITEM_ACTIVE = '1' "+
                    " and COMPUTE_DAILY_DATE is not null AND COMPUTE_DAILY_DATE != '' " +
                    " and (PAY_BY_CASH='Y' OR PAY_BY_AR='Y' OR PAY_BY_DOCTOR='Y' OR PAY_BY_PAYOR='Y' OR PAY_BY_CASH_AR='Y')" +
                    " and IS_PAID = 'Y' " +
                    " Group By DOCTOR_CODE order by DOCTOR_CODE";
    }
    
    static public String getSQLSum_DAILYwithExcludeTreatment_N(String hospitalCode) {
        return  "select DOCTOR_CODE, sum(AMOUNT_AFT_DISCOUNT) as sinv_amt, sum(AMOUNT_OF_DISCOUNT) as sinv_discount_amt, " + 
                " sum(DR_AMT) as sDr_Amt,sum(DR_TAX_400) as sDr_Amt_400, sum(DR_TAX_401) as sDr_Amt_401, " + 
                " sum(DR_TAX_402) as sDr_Amt_402, sum(DR_TAX_406) as sDr_Amt_406,  sum(DR_PREMIUM) as sDr_Premium,  " + 
                " sum(HP_AMT) as sHp_Amt, sum(HP_PREMIUM) as sHp_Premium, sum(HP_TAX) as sHp_Tax,  " + 
                " sum(0) as sRec_Amt, sum(0) as sRec_Premium_Amt,  sum(PREMIUM_REC_AMT) as sPremium_Rec_Amt, " + 
                " SUM( CASE PAY_BY_AR WHEN 'Y' THEN 0 ELSE DR_AMT END ) AS sDr_Amt_CASH, " +
                " SUM( CASE PAY_BY_AR WHEN 'Y' THEN DR_AMT ELSE 0 END ) AS sDr_Amt_AR, " +
                //sum
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN 0 ELSE DR_AMT END) AS sCash_Amt,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN 0 ELSE DR_TAX_400 END) AS sCash_400,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN 0 ELSE DR_TAX_401 END) AS sCash_401,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN 0 ELSE DR_TAX_402 END) AS sCash_402,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN 0 ELSE DR_TAX_406 END) AS sCash_406,  " +

                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN DR_AMT ELSE 0 END) AS sAr_Amt,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN DR_TAX_400 ELSE 0 END) AS sAr_400,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN DR_TAX_401 ELSE 0 END) AS sAr_401,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN DR_TAX_402 ELSE 0 END) AS sAr_402,  " +
                " SUM(CASE PAY_BY_AR WHEN 'Y' THEN DR_TAX_406 ELSE 0 END) AS sAr_406 " +
                //" FROM TRN_DAILY LEFT OUTER JOIN ORDER_ITEM ON TRN_DAILY.HOSPITAL_CODE = ORDER_ITEM.HOSPITAL_CODE" +
                //" AND TRN_DAILY.ORDER_ITEM_CODE = ORDER_ITEM.CODE"+
                " FROM TRN_DAILY"+
                    " where HOSPITAL_CODE ='" + hospitalCode + "'" + 
                    " and (BATCH_NO is null or BATCH_NO = '')" + 
                    " and EXCLUDE_TREATMENT != 'Y' " +       // very important
                    " and YYYY='" + Batch.getYyyy() + "' and MM='" + Batch.getMm() + "'" +
                    " and DOCTOR_CODE is not null AND DOCTOR_CODE != '' " +
                    " and ACTIVE = '1' " +
                    " and ORDER_ITEM_ACTIVE = '1' "+
                    " and COMPUTE_DAILY_DATE is not null AND COMPUTE_DAILY_DATE != '' " +
                    " and (PAY_BY_CASH='Y' OR PAY_BY_AR='Y' OR PAY_BY_DOCTOR='Y' OR PAY_BY_PAYOR='Y' OR PAY_BY_CASH_AR='Y')" +
                    " and IS_PAID = 'Y' " +
                    " Group By DOCTOR_CODE order by DOCTOR_CODE";
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }
    
    public String getDoctorCode() {
        return this.doctorCode;
    }

    public Double getDrCreditAmt() {
        return this.drCreditAmt;
    }

    public Double getDrDebitAmt() {
        return this.drDebitAmt;
    }

    public Double getDrDiscAmt() {
        return this.drDiscAmt;
    }

    public Double getDrNetPaidAmt() {
        this.drNetPaidAmt = JNumber.setFormat(this.drNetPaidAmt, JNumber.FORMAT_MONEY);
        return this.drNetPaidAmt;
    }

    public Double getDrPremiumAmt() {
        return this.drPremiumAmt;
    }

    public Double getDrSumAmt() {
        return this.drSumAmt;
    }

    public Double getDrTax402() {
        return this.drTax402;
    }

    public Double getDrTax406() {
        return this.drTax406;
    }

    public String getHospitalCode() {
        return this.hospitalCode;
    }

    public Double getHpDiscAmt() {
        return this.hpDiscAmt;
    }

    public Double getHpPremiumAmt() {
        return this.hpPremiumAmt;
    }

    public Double getHpSumAmt() {
        return this.hpSumAmt;
    }

    public Double getHpTax() {
        return this.hpTax;
    }

    public String getMm() {
        return this.mm;
    }

    public Double getSumAmt() {
        return this.sumAmt;
    }

    public Double getSumDiscAmt() {
        return this.sumDiscAmt;
    }

    public Double getSumPatientPaidAmt() {
        return this.sumPatientPaidAmt;
    }

    public Double getSumPremiumAmt() {
        return this.sumPremiumAmt;
    }

    public String getTransactionDate() {
        return this.transactionDate;
    }

    public String getYyyy() {
        return this.yyyy;
    }

    public void setDoctorCode(String doctorCode) {
        this.doctorCode = doctorCode;
    }

    public void setDrCreditAmt(Double drCreditAmt) {
        this.drCreditAmt = drCreditAmt;
    }

    public void setDrDebitAmt(Double drDebitAmt) {
        this.drDebitAmt = drDebitAmt;
    }

    public void setDrDiscAmt(Double drDiscAmt) {
        this.drDiscAmt = drDiscAmt;
    }

    public void setDrNetPaidAmt(Double drNetPaidAmt) {
        this.drNetPaidAmt = drNetPaidAmt;
    }

    public void setDrPremiumAmt(Double drPremiumAmt) {
        this.drPremiumAmt = drPremiumAmt;
    }

    public void setDrSumAmt(Double drSumAmt) {
        this.drSumAmt = drSumAmt;
    }

    public void setDrTax402(Double drTax402) {
        this.drTax402 = drTax402;
    }

    public void setDrTax406(Double drTax406) {
        this.drTax406 = drTax406;
    }

    public void setHospitalCode(String hospitalCode) {
        this.hospitalCode = hospitalCode;
    }

    public void setHpDiscAmt(Double hpDiscAmt) {
        this.hpDiscAmt = hpDiscAmt;
    }

    public void setHpPremiumAmt(Double hpPremiumAmt) {
        this.hpPremiumAmt = hpPremiumAmt;
    }

    public void setHpSumAmt(Double hpSumAmt) {
        this.hpSumAmt = hpSumAmt;
    }

    public void setHpTax(Double hpTax) {
        this.hpTax = hpTax;
    }

    public void setMm(String mm) {
        this.mm = mm;
    }

    public void setSumAmt(Double sumAmt) {
        this.sumAmt = sumAmt;
    }

    public void setSumDiscAmt(Double sumDiscAmt) {
        this.sumDiscAmt = sumDiscAmt;
    }

    public void setSumPatientPaidAmt(Double sumPatientPaidAmt) {
        this.sumPatientPaidAmt = sumPatientPaidAmt;
    }

    public void setSumPremiumAmt(Double sumPremiumAmt) {
        this.sumPremiumAmt = sumPremiumAmt;
    }

    public void setTransactionDate(String transactionDate) {
        this.transactionDate = transactionDate;
    }

    public void setYyyy(String yyyy) {
        this.yyyy = yyyy;
    }

    public Double getDrTax400() {
        return drTax400;
    }

    public void setDrTax400(Double drTax400) {
        this.drTax400 = drTax400;
    }

    public Double getDrTax401() {
        return drTax401;
    }

    public void setDrTax401(Double drTax401) {
        this.drTax401 = drTax401;
    }

    public Double getSumPayByAR() {
        return sumPayByAR;
    }

    public void setSumPayByAR(Double sumPayByAR) {
        this.sumPayByAR = sumPayByAR;
    }

    public Double getSumPayByCash() {
        return sumPayByCash;
    }

    public void setSumPayByCash(Double sumPayByCash) {
        this.sumPayByCash = sumPayByCash;
    }

    public Double getAr400() {
        return ar400;
    }

    public void setAr400(Double ar400) {
        this.ar400 = ar400;
    }

    public Double getAr401() {
        return ar401;
    }

    public void setAr401(Double ar401) {
        this.ar401 = ar401;
    }

    public Double getAr402() {
        return ar402;
    }

    public void setAr402(Double ar402) {
        this.ar402 = ar402;
    }

    public Double getAr406() {
        return ar406;
    }

    public void setAr406(Double ar406) {
        this.ar406 = ar406;
    }

    public Double getArAmt() {
        return arAmt;
    }

    public void setArAmt(Double arAmt) {
        this.arAmt = arAmt;
    }

    public Double getCash400() {
        return cash400;
    }

    public void setCash400(Double cash400) {
        this.cash400 = cash400;
    }

    public Double getCash401() {
        return cash401;
    }

    public void setCash401(Double cash401) {
        this.cash401 = cash401;
    }

    public Double getCash402() {
        return cash402;
    }

    public void setCash402(Double cash402) {
        this.cash402 = cash402;
    }

    public Double getCash406() {
        return cash406;
    }

    public void setCash406(Double cash406) {
        this.cash406 = cash406;
    }

    public Double getCashAmt() {
        return cashAmt;
    }

    public void setCashAmt(Double cashAmt) {
        this.cashAmt = cashAmt;
    }

    public String getIsHold() {
        return isHold;
    }

    public void setIsHold(String isHold) {
        if (isHold == null) { isHold = ""; }
        this.isHold = isHold;
    }
    
    public boolean insert() {
        boolean ret = false;
        String sql = "select * from " + this.getTableName() + " where YYYY='0000'";
        try {
            // Create an updatable result set
            if (this.getStatement() == null) { this.setStatement(this.getDBConnection().getConnection().createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)); }
            if (this.getResultSet() == null) {this.setResultSet(this.getStatement().executeQuery(sql));}
            // Move cursor to the "insert row"
            this.getResultSet().moveToInsertRow();
            
            // Set values for the new row.
            this.getResultSet().updateString("YYYY", this.getYyyy());
            this.getResultSet().updateString("MM", this.getMm());
            this.getResultSet().updateString("HOSPITAL_CODE", this.getHospitalCode());
            this.getResultSet().updateString("DOCTOR_CODE", this.getDoctorCode());
            this.getResultSet().updateString("Transaction_Date", this.getTransactionDate());
            this.getResultSet().updateDouble("SUM_AMT", this.getSumAmt());
            this.getResultSet().updateDouble("Sum_Disc_Amt", this.getSumDiscAmt());
            this.getResultSet().updateDouble("Sum_Premium_Amt", this.getSumPremiumAmt());
            this.getResultSet().updateDouble("Sum_Patient_Paid_Amt", this.getSumPatientPaidAmt());
            this.getResultSet().updateDouble("DR_SUM_AMT", this.getDrSumAmt());
            this.getResultSet().updateDouble("DR_Disc_Amt", this.getDrDiscAmt());
            this.getResultSet().updateDouble("DR_Premium_Amt", this.getDrPremiumAmt());
            this.getResultSet().updateDouble("DR_Credit_Amt", this.getDrCreditAmt());
            this.getResultSet().updateDouble("DR_Debit_Amt", this.getDrDebitAmt());
            this.getResultSet().updateDouble("DR_NET_PAID_AMT", this.getDrNetPaidAmt());
            this.getResultSet().updateDouble("DR_Tax_400", this.getDrTax400());
            this.getResultSet().updateDouble("DR_Tax_401", this.getDrTax401());
            this.getResultSet().updateDouble("DR_Tax_402", this.getDrTax402());
            this.getResultSet().updateDouble("DR_TAX_406", this.getDrTax406());
            this.getResultSet().updateDouble("HP_SUM_AMT", this.getHpSumAmt());
            this.getResultSet().updateDouble("HP_Disc_Amt", this.getHpDiscAmt());
            this.getResultSet().updateDouble("HP_Premium_Amt",this.getHpPremiumAmt());
            this.getResultSet().updateDouble("HP_TAX", this.getHpTax());
            this.getResultSet().updateString("UPDATE_DATE", this.getUpdateDate());
            this.getResultSet().updateString("Update_Time", this.getUpdateTime());
            this.getResultSet().updateString("USER_ID", this.getUserID());
            this.getResultSet().updateDouble("Guaruntee_Amt", this.getGuarunteeAmt());
            this.getResultSet().updateDouble("Guaruntee_Tax", this.getGuarunteeTax());
            this.getResultSet().updateString("STATUS_MODIFY", this.getStatusModify());
            this.getResultSet().updateString("BATCH_NO", this.getBatchNo());
            this.getResultSet().updateString("OLD_DOCTOR_CODE", this.getDoctorCode());
            this.getResultSet().updateString("Remark", this.getRemark());
            this.getResultSet().updateString("Payment_Mode_Code", this.getPaymentModeCode());
            this.getResultSet().updateString("Ref_Paid_No", this.getRefPaidNo());
            this.getResultSet().updateString("PAY_DATE", this.getPayDate());
            this.getResultSet().updateString("Payment_Term_Date", this.getPaymentTermDate());
            this.getResultSet().updateDouble("DR_Step_Amt", this.getDrStepAmt());
            this.getResultSet().updateDouble("HP_Step_Amt", this.getHpStepAmt());
            this.getResultSet().updateDouble("Sum_Premium_Rec_Amt", this.getSumPremiumRecAmt());
            this.getResultSet().updateDouble("SUM_PAY_BY_CASH", this.getSumPayByCash());
            this.getResultSet().updateDouble("SUM_PAY_BY_AR", this.getSumPayByAR());
            
            this.getResultSet().updateDouble("CASH_AMT", this.getCashAmt());
            this.getResultSet().updateDouble("CASH_400", this.getCash400());
            this.getResultSet().updateDouble("CASH_401", this.getCash401());
            this.getResultSet().updateDouble("CASH_402", this.getCash402());
            this.getResultSet().updateDouble("CASH_406", this.getCash406());
            this.getResultSet().updateDouble("AR_AMT", this.getArAmt());
            this.getResultSet().updateDouble("AR_400", this.getAr400());
            this.getResultSet().updateDouble("AR_401", this.getAr401());
            this.getResultSet().updateDouble("AR_402", this.getAr402());
            this.getResultSet().updateDouble("AR_406", this.getAr406());
            
            this.getResultSet().updateString("IS_HOLD", this.getIsHold());
            
            // Insert the row
            this.getResultSet().insertRow();
            ret=true;
        } catch (SQLException e) {
            e.printStackTrace();
            TRN_Error.writeErrorLog(this.getDBConnection().getConnection(),
                    TRN_Error.PROCESS_SUMMARY_MONTHLY, "Duplicate data.", e.getMessage());
        }
        finally {
                    }
        return ret;
    }

    public Double getGuarunteeAmt() {
        return guarunteeAmt;
    }

    public void setGuarunteeAmt(Double guarunteeAmt) {
        this.guarunteeAmt = guarunteeAmt;
    }

    public Double getGuarunteeTax() {
        return guarunteeTax;
    }

    public void setGuarunteeTax(Double guarunteeTax) {
        this.guarunteeTax = guarunteeTax;
    }

    public String getStatusModify() {
        return statusModify;
    }

    public void setStatusModify(String statusModify) {
        this.statusModify = statusModify;
    }

    public String getBatchNo() {
        return batchNo;
    }

    public void setBatchNo(String batchNo) {
        this.batchNo = batchNo;
    }
    // not used
    public boolean setStatusCalculated() {
        boolean ret = false;
        String sql = "update SUMMARY_MONTHLY set STATUS_MODIFY='" + Status.STATUS_CALCULATED + "'";
        sql = sql + " ,YYYY ='" + Batch.getYyyy() + "'";
        sql = sql + " ,MM ='" + Batch.getMm() + "'";
        sql = sql + " ,UPDATE_DATE='" + JDate.getDate() + "'";
        sql = sql + " ,Update_Time='" + JDate.getTime() + "'";
        sql = sql + " where HOSPITAL_CODE='" + this.hospitalCode + "'";
        sql = sql + " and DOCTOR_CODE='" + this.doctorCode + "'";
        sql = sql + " and (BATCH_NO is null or BATCH_NO = '')";
        sql = sql + " and (STATUS_MODIFY <> '" + Status.STATUS_CALCULATED + "' or STATUS_MODIFY is null or STATUS_MODIFY = '')";
        if (this.conn.executeUpdate(sql)>-1) {
            ret = true;
        } 
        return ret;
    }
    // not used
    public boolean setSummaryDailyStatusCalculated() {
        boolean ret = false;
        String sql = "update SUMMARY_DAILY set STATUS_MODIFY='" + Status.STATUS_CALCULATED + "'";
        sql = sql + " where HOSPITAL_CODE='" + this.hospitalCode + "'";
        sql = sql + " and DOCTOR_CODE='" + this.doctorCode + "'";
        sql = sql + " and (BATCH_NO is null or BATCH_NO = '')";
        sql = sql + " and (STATUS_MODIFY <> '" + Status.STATUS_CALCULATED + "' or STATUS_MODIFY is null or STATUS_MODIFY='')";
        if (this.conn.executeUpdate(sql)>-1) {
            ret = true;
        } 
        return ret;
    }
    
    public boolean update() {
        boolean ret = true;
/*        String sql = "select STATUS_MODIFY from SUMMARY_DAILY";
        sql = sql + " where HOSPITAL_CODE='" + this.hospitalCode + "'";
        sql = sql + " and DOCTOR_CODE='" + this.doctorCode + "'";
        sql = sql + " and (BATCH_NO is null or BATCH_NO = '')";
        sql = sql + " and (STATUS_MODIFY <> '" + Status.STATUS_CALCULATED + "' or STATUS_MODIFY is null or STATUS_MODIFY='')";

        
        try {
            if (getRs() == null) {
                setRs(getStmt().executeQuery(sql));
            } 
            
            int i=0;
            while (this.getRs().next()) {
                i ++;
                getRs().absolute(i); 
                this.getRs().updateString("STATUS_MODIFY", Status.STATUS_CALCULATED);
                
                // Insert the row
                this.getRs().updateRow();
            }
                ret = true;
        } catch (SQLException e) {
            e.printStackTrace();
        }
            
        finally {
              try {
                if (getRs() != null) {
                    getRs().close();
                    setRs(null);
                }
                if (getStmt() != null) {
                    getStmt().close();
                    setStmt(null);
                }
              }
              catch (SQLException ex)  {
                System.out.println("A SQLException error has occured in " + this.getClass().getName() + ".update() \n" + ex.getMessage());
                ex.printStackTrace();
                ret = false;
              }
        }
        */
        
        return ret;
    }
    
    public String getUserID() {
        return userID;
    }

    public void setUserID(String userID) {
        this.userID = userID;
    }

    public String getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(String updateDate) {
        this.updateDate = updateDate;
    }

    public String getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }
    
//    public boolean rollBackUpdate(String hospitalCode, String yyyy, String mm) {
//        List sqlCommand = new ArrayList();
//        boolean ret = false;
//        String sql1 = "update SUMMARY_MONTHLY set STATUS_MODIFY = 'R', UPDATE_DATE = '', UPDATE_TIME=''";
//                sql1 = sql1 + " ,remark = '', PAYMENT_MODE_CODE='', ref_paid_no = '', PAY_DATE = ''";
//                sql1 = sql1 + " WHERE YYYY='" + yyyy + "'";
//                sql1 = sql1 + " AND MM='"+ mm + "'";
//                sql1 = sql1 + " and HOSPITAL_CODE = '" + hospitalCode + "'";
//                
//        sqlCommand.add( sql1 );
//        ret = super.rollBack(sqlCommand);
//        return ret;
//    }
    
    public boolean rollBackDelete(String hospitalCode, String yyyy, String mm) {
        List sqlCommand = new ArrayList();
        boolean ret = false;
        String sql1 = "delete from " + this.getTableName() + " WHERE YYYY='" + yyyy + "'"
                + " AND MM = '" + mm + "'"
                + " and HOSPITAL_CODE = '" + hospitalCode + "'"
                + " and (BATCH_NO IS NULL OR BATCH_NO = '')";
        sqlCommand.add( sql1 );
        ret = super.rollBack(sqlCommand);
        return ret;
    }
    
    
    public String getOldDoctorCode() {
        return oldDoctorCode;
    }

    public void setOldDoctorCode(String oldDoctorCode) {
        this.oldDoctorCode = oldDoctorCode;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getPaymentModeCode() {
        return paymentModeCode;
    }

    public void setPaymentModeCode(String paymentModeCode) {
        this.paymentModeCode = paymentModeCode;
    }

    public String getRefPaidNo() {
        return refPaidNo;
    }

    public void setRefPaidNo(String refPaidNo) {
        if (refPaidNo == null) refPaidNo = ""; 
        this.refPaidNo = refPaidNo;
    }

    public String getPayDate() {
        return payDate;
    }

    public void setPayDate(String payDate) {
        if (payDate == null) { payDate = ""; }
        this.payDate = payDate;
    }

    public String getPaymentTermDate() {
        return paymentTermDate;
    }

    public void setPaymentTermDate(String paymentTermDate) {
        if (paymentTermDate == null) { paymentTermDate = ""; }
        this.paymentTermDate = paymentTermDate;
    }

    public Double getDrStepAmt() {
        return drStepAmt;
    }

    public void setDrStepAmt(Double drStepAmt) {
        this.drStepAmt = drStepAmt;
    }

    public Double getHpStepAmt() {
        return hpStepAmt;
    }

    public void setHpStepAmt(Double hpStepAmt) {
        this.hpStepAmt = hpStepAmt;
    }

    public Double getSumPremiumRecAmt() {
        return sumPremiumRecAmt;
    }

    public void setSumPremiumRecAmt(Double sumPremiumRecAmt) {
        this.sumPremiumRecAmt = sumPremiumRecAmt;
    }
    
}
